﻿Imports lbGlobalcom
Public Class fProductos
    Dim daDatosTablas As lbGlobalcom.dsGlobalTableAdapters.GLO_DATOSTABLASTableAdapter
    Dim daTipoProd As lbGlobalcom.dsProductosTableAdapters.PRO_TIPOPRODUCTOTableAdapter
    Dim daTipoIva As lbGlobalcom.dsContabilidadTableAdapters.CON_TIPOIVATableAdapter
    Dim daProd As lbGlobalcom.dsProductosTableAdapters.PRO_PRODUCTOTableAdapter


    Private Sub btnBuscaTipoProd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscaTipoProd.Click
        Dim fLTipoP As New fListaTipoProducto
        If fLTipoP.ShowDialog = Windows.Forms.DialogResult.OK Then
            IDTIPOPRODUCTOTextBox.Text = fLTipoP.idTipoProd
        End If
    End Sub

    Private Sub IDTIPOPRODUCTOTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IDTIPOPRODUCTOTextBox.TextChanged
        If IDTIPOPRODUCTOTextBox.Text.Trim.Length > 0 Then
            Me.lbTipoProducto.Text = daTipoProd.GetNombreTipo(IDTIPOPRODUCTOTextBox.Text)
        End If
    End Sub
    
    Private Sub fProductos_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        daTipoProd = New lbGlobalcom.dsProductosTableAdapters.PRO_TIPOPRODUCTOTableAdapter
        daTipoIva = New lbGlobalcom.dsContabilidadTableAdapters.CON_TIPOIVATableAdapter
        daProd = New lbGlobalcom.dsProductosTableAdapters.PRO_PRODUCTOTableAdapter
        daDatosTablas = New lbGlobalcom.dsGlobalTableAdapters.GLO_DATOSTABLASTableAdapter
        Try
            lbGlobalcom.cGeneral.ActivaControles(Me.Controls, False)
            daDatosTablas.FillByIdGrupo(DsGlobal.GLO_DATOSTABLAS, "es")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btnBuscaTipoIva_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscaTipoIva.Click
        Dim fLTI As New fListaTipoIva
        If fLTI.ShowDialog = Windows.Forms.DialogResult.OK Then
            IDTIPOIVATextBox.Text = fLTI.TipoIva
        End If
    End Sub

    Private Sub IDTIPOIVATextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IDTIPOIVATextBox.TextChanged
        If IDTIPOIVATextBox.Text.Trim.Length > 0 Then
            Me.lbTipoIVA.Text = daTipoIva.getNombreTipoIva(IDTIPOIVATextBox.Text)
        End If
    End Sub

    Private Sub PRO_PRODUCTOBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PRO_PRODUCTOBindingNavigatorSaveItem.Click
        Try
            PRO_PRODUCTOBindingSource.EndEdit()
            daProd.Update(DsProductos.PRO_PRODUCTO)
            MessageBox.Show("Se salvarón productos con exito", "Salva Productos", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Try
            If MessageBox.Show("Esta seguro que desea eliminar este producto", "Elimina Producto", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                PRO_PRODUCTOBindingSource.EndEdit()
                PRO_PRODUCTOBindingSource.Remove(PRO_PRODUCTOBindingSource.Current)
                daProd.Update(DsProductos.PRO_PRODUCTO)
                MessageBox.Show("Se elimino producto con exito", "Elimina Producto", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub btnBuscaProducto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscaProducto.Click
        Try
            Dim flArt As New fListaProductos
            If flArt.ShowDialog = Windows.Forms.DialogResult.OK Then
                If DsProductos.PRO_PRODUCTO.GetChanges IsNot Nothing Then
                    If MessageBox.Show("Hay productos pendientes por salvar, desea salvarlos", "Cambios Pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                        daProd.Update(DsProductos.PRO_PRODUCTO)
                    End If
                End If
                daProd.FillByIdProducto(DsProductos.PRO_PRODUCTO, flArt.idArticulo)
                lbGlobalcom.cGeneral.ActivaControles(Me.Controls, True)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click
        Try
            lbGlobalcom.cGeneral.ActivaControles(Me.Controls, True)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class